package com.jlnk.stockdemo.bean;

import com.google.gson.annotations.SerializedName;

import java.util.ArrayList;
import java.util.List;

public class StockListResponse {

    @SerializedName("request_id")
    private String requestId;

    @SerializedName("code")
    private int code;

    @SerializedName("data")
    private StockListResponse.Data data;

    @SerializedName("msg")
    private String msg;

    public String getRequestId() {
        return requestId;
    }

    public int getCode() {
        return code;
    }

    public StockListResponse.Data getData() {
        return data;
    }

    public String getMsg() {
        return msg;
    }

    public static class Data {
        @SerializedName("fields")
        private List<String> fields;

        @SerializedName("items")
        private List<List<String>> items;

        @SerializedName("has_more")
        private boolean hasMore;

        @SerializedName("count")
        private int count;

        private List<Stock> stockList;

        public List<String> getFields() {
            return fields;
        }

        public List<List<String>> getItems() {
            return items;
        }

        public boolean isHasMore() {
            return hasMore;
        }

        public int getCount() {
            return count;
        }

        public List<Stock> getStockList() {
            stockList = new ArrayList<>();
            int tsCodeIndex, symbolIndex, nameIndex, areaIndex, industryIndex, marketIndex;
            tsCodeIndex = symbolIndex = nameIndex = areaIndex = industryIndex = marketIndex =0;
            for (int i = 0; i < fields.size(); i++) {
                switch (fields.get(i)) {
                    case "ts_code" :
                        tsCodeIndex = i;
                        break;
                    case "symbol" :
                        symbolIndex = i;
                        break;
                    case "name" :
                        nameIndex = i;
                        break;
                    case "area" :
                        areaIndex = i;
                        break;
                    case "industry" :
                        industryIndex = i;
                        break;
                    case "market" :
                        marketIndex = i;
                        break;
                }
            }
            for (int j = 0; j < items.size(); j++) {
                Stock stock = new Stock();
                stock.setTsCode(items.get(j).get(tsCodeIndex));
                stock.setSymbol(items.get(j).get(symbolIndex));
                stock.setName(items.get(j).get(nameIndex));
                stock.setArea(items.get(j).get(areaIndex));
                stock.setIndustry(items.get(j).get(industryIndex));
                stock.setMarket(items.get(j).get(marketIndex));
                stockList.add(stock);
            }
            return stockList;
        }

        public static class Stock {
            private String tsCode;
            private String symbol;
            private String name;
            private String area;
            private String industry;
            private String market;

            public String getTsCode() {
                return tsCode;
            }

            public void setTsCode(String tsCode) {
                this.tsCode = tsCode;
            }

            public String getSymbol() {
                return symbol;
            }

            public void setSymbol(String symbol) {
                this.symbol = symbol;
            }

            public String getName() {
                return name;
            }

            public void setName(String name) {
                this.name = name;
            }

            public String getArea() {
                return area;
            }

            public void setArea(String area) {
                this.area = area;
            }

            public String getIndustry() {
                return industry;
            }

            public void setIndustry(String industry) {
                this.industry = industry;
            }

            public String getMarket() {
                return market;
            }

            public void setMarket(String market) {
                this.market = market;
            }
        }
    }
}
